#include "Input.hpp"

Input::Input()
{
	for(int i =0; i < KeysCount; i++)
	{
		m_keyDown[i] = false;
	}
}

bool Input::isKeyDown(Key k) const
{
	return m_keyDown[k];
}


void Input::updateKey(Key k, bool isDown)
{
	m_keyDown[k] = isDown;
}

void Input::pushEvent(sf::Event event)
{
	Key theKey;
	switch(event.type)
	{
	case sf::Event::KeyPressed:
		if(convertKey(event.key.code, theKey))
			updateKey(theKey, true);
		return;
	case sf::Event::KeyReleased:
		if(convertKey(event.key.code, theKey))
			updateKey(theKey, false);
		return;
	default:
		return;
	}
}

bool Input::convertKey(sf::Keyboard::Key keyIn, Key& keyOut)
{
	switch(keyIn)
	{
	case sf::Keyboard::Up:
		keyOut = Up_Arrow;
		return true;
	case sf::Keyboard::Down:
		keyOut = Down_Arrow;
		return true;
	case sf::Keyboard::Left:
		keyOut = Left_Arrow;
		return true;
	case sf::Keyboard::Right:
		keyOut = Right_Arrow;
		return true;
	case sf::Keyboard::D:
		keyOut = Debug_Key;
		return true;
	default:
		return false;
	}
}
